/**
 *
 */
package cn.dw.sg.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author aubrey
 * @date  下午5:22:00
 * 
 */
//@WebFilter("/*")
public class TestFilter implements Filter {

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {

	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest)request;
		
		HttpSession session = req.getSession();
		session.setAttribute("name", "张三");
		
		if(session.getAttribute("name") == null) {
			req.getRequestDispatcher("index.jsp").forward(request, response);
		};
		
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {

	}

}
